package com.ys.fmms.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

import javax.servlet.Filter;

@Configuration
public class FilterRegistrationConfig  {

    @Bean
    public FilterRegistrationBean<CharacterEncodingFilter> filterRegistrationBean() {
        FilterRegistrationBean<CharacterEncodingFilter> bean = new FilterRegistrationBean<>();
        // 使用框架中的字符过滤器
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        // 设置编码方式
        filter.setEncoding("utf-8");
        // 指定request response 都使用encoding的值
        filter.setForceEncoding(true);
        bean.setFilter(filter);
        // 指定过滤的url地址
        bean.addUrlPatterns("/*");
        return bean;
    }

}
